#ifndef _PERSEUSHTTP_H__
#define _PERSEUSHTTP_H__

#include <stdlib.h>
#include "perseus.h"

#define PERSEUS_SEP "perseus"
#define PERSEUS_SEP_LENGTH 7
#define PERSEUS_MAX_LENGTH 8192


typedef enum PERSEUS_MODE
{
    PERSEUS_CODE,
    PERSEUS_DECODE
}PERSEUS_MODE_t;
/* 
 * HTTP : Perseus supported only two
 * encoded type : 
 *      PERSEUS_URLENCODED : application/x-www-form-urlencoded
 *      PERSEUS_MULTIPARTFORMDATA : multipart/form-data
 */
typedef enum PERSEUS_CTYPE
{
    PERSEUS_URLENCODED,
    PERSEUS_MULTIPARTFORMDATA,
    PERSEUS_GET,
    PERSEUS_UNSUPPORTED
}PERSEUS_CTYPE_t;


unsigned int
readHeader(char * request, unsigned long requestLength);

unsigned char 
findPerseusSEP(char * request, unsigned long requestLength,
		unsigned long * PerseusSEPposition);

unsigned char
perseusHTTPdecode(pcc * code,
		  char * request, unsigned long  requestLength,
		  char ** dataDecoded, unsigned long * dataDecodedLength,
		  unsigned long *dataRest);
unsigned char
gotoEndtheLine(char ** data, unsigned long * length);

unsigned char
isCRLF(char * request, unsigned long requestLength);

unsigned char
isTheEndOfMultipart(char * request, unsigned long requestLength);

unsigned int
readHeader(char * request, unsigned long requestLength);

unsigned char
isBoundary(char *request, unsigned long requestLength,
	     const char * boundary, unsigned int boundaryLength);

char *
parseUrlEncoded(char * body, unsigned long bodyLength, pcc * PerseusParam, PERSEUS_MODE_t mode);
char *
parseGet(char * body, unsigned long bodyLength, pcc * PerseusParam, PERSEUS_MODE_t mode);

char *
parseMultipart(char * body, unsigned long length, pcc* PerseusParam, PERSEUS_MODE_t mode);

pcc *
parsePCC(char * data, unsigned int length);

char *
pcc2string(pcc * params);

char * 
itoa2(int value, char* result, int base);

unsigned char
perseusHTTPencode(pcc * code, char * data, unsigned long dataLength,
                    char ** dataEncoded, unsigned long *dataEncodedLength);

char *
addData(char ** res, unsigned long *resLength,
        char * data, unsigned long dataLength);

#endif /*_PERSEUSHTTP_H__*/
